﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bootstrap5.Design;

class GutterDefinition:BreakingPointModel
{
   public SpaceSide? Side { get; set; }
}

internal class GutterProvider : BreakPointClassDecoratorProvider<GridSize, GutterDefinition, IGutterDecorator>, IGutterDecorator
{
    public IGutterDecorator FromX => GetSide(SpaceSide.X);

    public IGutterDecorator FromY => GetSide(SpaceSide.Y);
    public IGutterDecorator Is0 => GetKey(GridSize.Is0);

    public IGutterDecorator Is1 => GetKey(GridSize.Is1);

    public IGutterDecorator Is2 => GetKey(GridSize.Is2);

    public IGutterDecorator Is3 => GetKey(GridSize.Is3);

    public IGutterDecorator Is4 => GetKey(GridSize.Is4);

    public IGutterDecorator Is5 => GetKey(GridSize.Is5);

    protected override IGutterDecorator GetBreakPoint(BreakPoint breakPoint)
    {
        SetBreakPoint(breakPoint);
        return this;
    }

    protected override IGutterDecorator GetKey(GridSize key)
    {
        SetKey(key);
        return this;
    }
    IGutterDecorator GetSide(SpaceSide side)
    {
        CurrentModel.Side = side;
        SetDirty();
        return this;
    }
    protected override void BuildClass()
    {
        Rules.AddRange(RuleDic.Select(m => GetCssClass(m.Key, m.Value)));
    }

    private string GetCssClass(GridSize size, IEnumerable<GutterDefinition> values)
    {
        return string.Join(" ", values.Select(m => GetCssClass(size, m.Side, m.BreakPoint)));
    }

    private string GetCssClass(GridSize size, SpaceSide? side, BreakPoint? breakPoint)
    {
        var builder = new StringBuilder("g");
        if (side.HasValue)
        {
            builder.Append(side.Value.GetEnumCssClass());
        }
        builder.Append(CssClassHelper.STRIPER);
        builder.Append(GetBreakPointString(breakPoint));
        builder.Append(size.GetEnumCssClass());
        return builder.ToString();
    }
}
